package com.int_tech.utils;

public class MoneyToFen {
	
	public static void main(String[] args) {
		
		String money = ".22";
		System.out.println(changeY2F(money));
		
	}
	
	public static String changeY2F(String amount){    
        String currency =  amount.replaceAll("\\$|\\￥|\\,", "");  //处理包含, ￥ 或者$的金额    
        int index = currency.indexOf(".");    
        int length = currency.length();    
        Long amLong = 0l;    
        if(index == -1){    
            amLong = Long.valueOf(currency+"00");    
        }else if(length - index >= 3){    
            amLong = Long.valueOf((currency.substring(0, index+3)).replace(".", ""));    
        }else if(length - index == 2){    
            amLong = Long.valueOf((currency.substring(0, index+2)).replace(".", "")+0);    
        }else{    
            amLong = Long.valueOf((currency.substring(0, index+1)).replace(".", "")+"00");    
        }    
        return amLong.toString();    
    } 
	

	public static String moneyToFen(String money){
		try
		{
			float fm = Float.parseFloat(money);
			int ntmp1 = (int)(fm*10);
			int ntmp2 = (int)(fm*100);
			int nm=ntmp2;
			if((ntmp2-ntmp1*10)>0)
			{
				nm=(ntmp1+1)*10;
			}
			money = String.valueOf(nm);
		}catch(Exception ex)
		{
			int ndot = money.indexOf(".");
			String nyuan = money.substring(0, ndot);
			String nfen=money.substring(ndot+1);
			String sfen="";
			if(nfen.length()==1)
			{
				sfen = nfen+"0";
			}
			else if(nfen.length()>=2)
			{
				String nTmp = nfen.substring(0,1);
				try
				{
					int nT = Integer.parseInt(nTmp)+1;
					sfen=Integer.toString(nT)+"0";
					
					if(nT==10)
					{
						int nTemp = Integer.parseInt(nyuan);
						nyuan = Integer.toString(nTemp+1);
						sfen="00";
					}
				}catch(Exception e)
				{
					try{
						int nTemp = Integer.parseInt(nyuan);
						nyuan = Integer.toString(nTemp+1);
						sfen="00";
					}catch(Exception ee)
					{
					}
				}
			}
			money=nyuan+sfen;
		}
		
		return money;
	}
}
